package com.wh.beans.custom;


import com.legend.utils.StringUtils;
import com.wh.model.CustomField;

import java.text.MessageFormat;

public class SelectUser implements ICustomLabel {

	@Override
	public String getCustomLabel(CustomField field, LabelType type) {
		String label = "", template = "";
		String fieldLittleName = StringUtils.getFieldLittleCamel(field.getFieldDbName());
		String fieldBigName = StringUtils.getFieldBigCamel(field.getFieldDbName());
		Float width = field.getInputWidth();
		Integer panelHeight = field.getInputHeight();
		//String defValue = "";
		StringBuffer s;
		if (panelHeight==null) {
			panelHeight=200;
		}
		if (width==null) {
			width=200f;
		}
		switch (type) {
		case add:
			boolean editable = (field.getInputProperty() & 32) == 32;
			s = new StringBuffer();
			s.append(MessageFormat
					.format("<select id=\"sl{0}\" class=\"easyui-combobox\" data-options=\"editable:{1},valueField:\''userId\'',textField:\''userName\'',url:\''userlist.do\''\" panelHeight=\"{2}\" name=\"{3}\" panelWidth=\"{4}\">",
                            fieldBigName, editable, panelHeight, fieldLittleName, width));
			s.append("</select>");
			label = s.toString();
			break;
		case edit:
			editable = (field.getInputProperty() & 32) == 32;
			s = new StringBuffer();
			//defValue = MessageFormat.format("$'{'info.data.{0}'}'", fieldLittleName);
			s.append(MessageFormat
					.format("<select id=\"sl{0}\" class=\"easyui-combobox\" data-options=\"editable:{1},valueField:\''userId\'',textField:\''userName\'',url:\''userlist.do\''\" panelHeight=\"{2}\" name=\"{3}\"  panelWidth=\"{4}\">",
							fieldBigName, editable, panelHeight, fieldLittleName, width));
			s.append("</select>");

			label = s.toString();
			break;
		case view:
			template = "未写实现";
			label = MessageFormat.format(template, fieldLittleName);
			break;
		default:
			break;
		}
		return label;
	}

}
